# -*- coding: utf-8 -*-

from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager, Server, Command
from werkzeug.contrib.fixers import ProxyFix

import vsogame.seeder as seeder
from app import create_app
from database import db


def internal_error(error):
    print('ERROR:', error)


def hello():
    return 'hello core'


class Seeder(Command):
    def __call__(self, *args, **kwargs):
        print('SEED')
        seeder.seed()


app = create_app()
app.wsgi_app = ProxyFix(app.wsgi_app)

manager = Manager(app)
# manager.add_command(Shell(make_context=lambda: dict(app=app, db=d)))
migrate = Migrate(app, db)

manager.add_command('runserver', Server(host='0.0.0.0', threaded=True, port='5000'))
manager.add_command('db', MigrateCommand)
manager.add_command('seed', Seeder)

if __name__ == '__main__':
    import sys
    import locale

    # type('vsogame.extensions.Model')
    print(locale.getdefaultlocale())
    # locale.setlocale(locale.LC_ALL, locale='zh_CN.cp936')
    print(locale.getpreferredencoding(False))
    default_encoding = 'utf-8'
    print(sys.getdefaultencoding())
    manager.run()
